package com.yequan.thread.pc;

public class Maker extends Thread {

    private Table table;
    private static int id = 0;//蛋糕的流水号,唯一标识

    public Maker(String name, Table table) {
        super(name);
        this.table = table;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(5000);
                String cake = "蛋糕师" + getName() + "制作了一个蛋糕,流水号为" + nextId();
                table.put(cake);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private synchronized static int nextId() {
        return id++;
    }
}
